package com.android.delivery.adapter

import android.text.TextUtils
import android.widget.ImageView
import android.widget.TextView
import com.android.delivery.R
import com.android.delivery.activity.OrderDetailsActivity
import com.android.delivery.activity.OrderSettleActivity
import com.android.delivery.entity.Logistics
import com.android.delivery.util.CopyUtil
import com.android.delivery.util.DateFormatUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * 揽件中心-已打印
 * @author: mqwang
 * @create: 3/18/21 1:33 PM
 * @Description:
 */
class LPrintAdapter : BaseQuickAdapter<Logistics, BaseViewHolder>(R.layout.adapter_printed) {

    override fun convert(helper: BaseViewHolder?, item: Logistics?) {

        helper!!.setText(R.id.tv_order_no, "订单号:" + item!!.logisticsNo)
        helper!!.setText(R.id.tv_order_date, "揽件时间:" + DateFormatUtil.formatDate(item.createdTime!!, "yyyy-MM-dd HH:mm:ss"))
        helper!!.setText(R.id.tv_name, item!!.senderName)
        helper!!.setText(R.id.tv_phone, item!!.senderMobile)
        helper!!.setText(R.id.tv_addr, item!!.senderAddress)

        if (item.payType == 1) {
            helper.setText(R.id.tv_way_pay, "寄付")
        } else if (item.payType == 2) {
            helper.setText(R.id.tv_way_pay, "到付")
        }

        if (item.type == OrderSettleActivity.TYPE_LINDAN_SEND) {
            helper.setText(R.id.tv_mark, "零担")
        } else if (item.type == OrderSettleActivity.TYPE_CITY_SEND) {
            helper.setText(R.id.tv_mark, "同城")
        } else {
            helper.setText(R.id.tv_mark, "速配")
        }

        if (TextUtils.isEmpty(item!!.receiverName)) {
            helper.setGone(R.id.receiver_gp, false)
        } else {
            helper.setGone(R.id.receiver_gp, true)
            helper!!.setText(R.id.tv_receiver_name, item!!.receiverName)
            helper!!.setText(R.id.tv_receiver_phone, item!!.receiverMobile)
            helper!!.setText(R.id.tv_receiver_addr, item!!.receiverAddress)
        }

        helper.setText(R.id.tv_money, String.format("%.2f元", item.payment))

        helper.getView<ImageView>(R.id.iv_copy).setOnClickListener {
            CopyUtil.ClipData(mContext, item.logisticsNo)
        }
        helper.getView<TextView>(R.id.tv_phone).setOnClickListener {
            CopyUtil.callPhone(mContext, item.senderMobile)
        }

        helper.getView<TextView>(R.id.tv_receiver_phone).setOnClickListener {
            CopyUtil.callPhone(mContext, item.receiverMobile)
        }

        helper.itemView.setOnClickListener {
            OrderDetailsActivity.self(mContext, item.logisticsNo)
        }

        helper.addOnClickListener(R.id.tv_1)
    }
}